﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Amoo.Code.Data
{
    public class Home: BaseData
    {

        public Entity.Home GetById(Entity.Home pHome)
        {
            IDataReader dr = ExecuteReader("select * from home where idcomunidade = " + pHome.idComunidade);
            if (dr != null)
            {
               if (dr.Read())
                {
                    return Entity.Home.Load(dr);
                }
            }
            return null;
        }

        internal void Alterar(Code.Entity.Home pHome)
        {
            string query = @"UPDATE home SET 
                            dsHome = '" + pHome.dsHtml + @"', 
                    WHERE idComunidade = " + pHome.idComunidade;
            Execute(query);
        }

        internal void Insert(Code.Entity.Home pHome)
        {
            string query = @"INSERT INTO home (idComunidade, dsHtml)
                   VALUES ({0}, '{1}')";
            query = string.Format(query, pHome.idComunidade.ToString(), pHome.dsHtml);
            Execute(query);
        }

        internal void Delete(Code.Entity.Home pHome)
        {
            string query = @"Delete from home WHERE idComunidade = " + pHome.idComunidade;
            Execute(query);
        }
        

    }
}
